create table #size (name varchar(30), rows int, reserved varchar(30), data varchar(30), index_size varchar(30), unused varchar(30)) set nocount on exec sp_msforeachtable 'set nocount on declare @x varchar(30) set @x = replace(replace(substring(''?'',7,50),''['',''''),'']'','''') insert #size exec sp_spaceused @x' update #size set reserved = case when charindex('KB',reserved) > 0 then replace(replace(reserved,'KB', ''),' ','') + '000' when charindex('MB', reserved) > 0 then substring(reserved,1,charindex('MB', reserved)) + '000000' end, data = case when charindex('KB',data) > 0 then replace(replace(data,'KB', ''),' ','') + '000' when charindex('MB', data) > 0 then substring(data,1,charindex('MB', data)) + '000000' end, index_size = case when charindex('KB',index_size) > 0 then replace(replace(index_size,'KB', ''),' ','') + '000' when charindex('MB', index_size) > 0 then substring(index_size,1,charindex('MB', index_size)) + '000000' end, unused = case when charindex('KB',unused) > 0 then replace(replace(unused,'KB', ''),' ','') + '000' when charindex('MB', unused) > 0 then substring(unused,1,charindex('MB', unused)) + '000000' end insert #size (name, rows, reserved, data, index_size, unused) select '_TOTAL', sum(rows), sum(cast(reserved as numeric(16,0))), sum(cast(data as numeric(16,0))), sum(cast(index_size as numeric(16,0))), sum(cast(unused as numeric(16,0))) from #size select name, rows, reserved, data, index_size, unused from #size --drop table #size